home *** CD-ROM | disk | FTP | other *** search
- unit uAddToGroup;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, TntStdCtrls, CheckLst, TntCheckLst, uSyncPhonebook,
- ExtCtrls, jpeg;
-
- type
- TfrmAddToGroup = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Panel1: TPanel;
- Label1: TLabel;
- RadioButton1: TRadioButton;
- RadioButton2: TRadioButton;
- lblName: TTntLabel;
- Label2: TLabel;
- lblGroup: TTntLabel;
- clNumbers: TTntCheckListBox;
- Bevel1: TBevel;
- Image1: TImage;
- Label3: TLabel;
- lbProductName: TLabel;
- lblNumber: TLabel;
- RadioButton3: TRadioButton;
- Button3: TButton;
- procedure RadioButtonClick(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- FContact: PContactData;
- procedure Set_Contact(const Value: PContactData);
- { Private declarations }
- public
- { Public declarations }
- function CheckedCount: integer;
- function GetNumber(Index: integer): string;
- property Contact: PContactData read FContact write Set_Contact;
- end;
-
- var
- frmAddToGroup: TfrmAddToGroup;
-
- implementation
-
- uses Unit1;
-
- {$R *.dfm}
-
- procedure TfrmAddToGroup.RadioButtonClick(Sender: TObject);
- begin
- clNumbers.Enabled := RadioButton2.Checked;
- if clNumbers.Enabled then clNumbers.Color := clWindow
- else clNumbers.Color := clBtnFace;
- end;
-
- procedure TfrmAddToGroup.Set_Contact(const Value: PContactData);
- var
- i: integer;
- begin
- FContact := Value;
- { Build contact numbers check list }
- clNumbers.Items.Clear;
- lblName.Caption := GetContactFullName(FContact);
- if FContact^.cell <> '' then clNumbers.Items.Add('Cell ['+FContact^.cell+']');
- if FContact^.work <> '' then clNumbers.Items.Add('Work ['+FContact^.work+']');
- if FContact^.home <> '' then clNumbers.Items.Add('Home ['+FContact^.home+']');
- if FContact^.other <> '' then clNumbers.Items.Add('Other ['+FContact^.other+']');
- if clNumbers.Count = 0 then
- raise Exception.Create('This contact does not have any phone number');
- { Find default number }
- lblNumber.Caption := GetContactDefPhone(FContact);
- for i := 0 to clNumbers.Count-1 do
- if GetNumber(i) = lblNumber.Caption then begin
- lblNumber.Caption := clNumbers.Items[i];
- break;
- end;
- { Update view }
- RadioButton1.Checked := True;
- RadioButtonClick(nil);
- end;
-
- procedure TfrmAddToGroup.Button1Click(Sender: TObject);
- var
- i: integer;
- begin
- if RadioButton3.Checked then begin
- for i := 0 to clNumbers.Count-1 do clNumbers.Checked[i] := True;
- RadioButton2.Checked := True;
- end;
- if CheckedCount = 0 then
- raise Exception.Create('You have to select at least one phone number');
- ModalResult := mrOk;
- end;
-
- function TfrmAddToGroup.CheckedCount: integer;
- var
- i: integer;
- begin
- if RadioButton2.Checked then begin
- Result := 0;
- for i := 0 to clNumbers.Count-1 do
- if clNumbers.Checked[i] then Result := Result + 1;
- end
- else
- Result := 1;
- end;
-
- procedure TfrmAddToGroup.FormCreate(Sender: TObject);
- begin
- {$IFNDEF VER150}
- Form1.ThemeManager1.CollectForms(Self);
- {$ENDIF}
- Image1.Picture.Assign(Form1.FmaWebUpdate1.Picture);
- lblName.Font.Style := lblName.Font.Style + [fsBold];
- end;
-
- function TfrmAddToGroup.GetNumber(Index: integer): string;
- var
- s: string;
- i: integer;
- begin
- if (Index >= 0) and (Index < clNumbers.Count) then begin
- { s is like 'Name [+number]' }
- s := clNumbers.Items[Index];
- i := Pos('[',s);
- Delete(s,1,i); // remove 'Name ['
- Delete(s,Length(s),1); // remove ']'
- Result := s;
- end
- else
- Result := '';
- end;
-
- end.
-